<?php

namespace App\Admin\Controllers;

use App\Admin\Repositories\FourCampus;
use Dcat\Admin\Form;
use Dcat\Admin\Grid;
use Dcat\Admin\Show;
use Dcat\Admin\Http\Controllers\AdminController;

class FourCampusController extends AdminController
{
    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        return Grid::make(new FourCampus(), function (Grid $grid) {
            $grid->column('id')->sortable();
            $grid->column('campus_name','院区');
            $grid->column('city','市');
            $grid->column('region','区');
            $grid->column('phone1','电话1');
            $grid->column('phone2','电话2');
            $grid->column('car','公交');
            $grid->column('in_navigation','院内导航');
            $grid->column('desc','院区描述');
            $grid->column('campus_status','状态');
            $grid->column('created_at','创建时间');
            $grid->column('updated_at','修改时间')->sortable();
            // 开启字段选择器功能
            $grid->showColumnSelector();
            $grid->filter(function (Grid\Filter $filter) {
                $filter->equal('id');

            });
        });
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     *
     * @return Show
     */
    protected function detail($id)
    {
        return Show::make($id, new FourCampus(), function (Show $show) {
            $show->field('id');
            $show->field('campus_name','院区');
            $show->field('city','市');
            $show->field('region','区');
            $show->field('phone1','电话1');
            $show->field('phone2','电话2');
            $show->field('car','公交');
            $show->field('in_navigation','院内导航');
            $show->field('desc','院区描述');
            $show->field('campus_status','状态');
            $show->field('created_at','创建时间');
            $show->field('updated_at','修改时间');
        });
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        return Form::make(new FourCampus(), function (Form $form) {
            $form->hidden('id');
            $form->text('campus_name','院区');
            $form->text('phone1','联系电话');
            $form->text('car','公交');
            $form->text('city','市');
            $form->text('region','区');
            $form->text('in_navigation','院内导航');
            $form->textarea('desc','院区描述');
//            $form->text('campus_status','状态');
//            // 添加开关操作
            $form->switch('campus_status', '状态');
            $form->display('created_at','创建时间');
            $form->display('updated_at','修改时间');
        });
    }
}
